#ifndef __ATMOS_Packet_h__
#define __ATMOS_Packet_h__

#include "ATMOS_Common.h"
#include "ATMOS_PacketID.h"

#include <string>

namespace RakNet {

class BitStream;

} // end namespace RakNet

namespace ATMOS {

//! the basic unit of network communication
class AtmosExport Packet
{
	Packet();
	Packet( const Packet &src );

public:
	//! constructor for an empty packet
	/*!
		\param packetID ATMOS packet ID for this instance
		\param rakNetGUID the GUID of the origin network manager
		*/
	Packet( PacketID packetID, const std::string &rakNetGUID );
	//! constructor for copying an existing RakNet or Atmos packet
	/*! this constructor copies the data from an existing RakNet packet
		\param packetID ATMOS packet ID for this instance
		\param rakNetGUID the GUID of the origin network manager
		*/
	Packet( unsigned char *data, unsigned int size );
	virtual ~Packet();

	//! get the RakNet GUID where this packet originated
	const std::string &getRakNetGUID() const;
	//! get the ATMOS packet ID of this instance
	PacketID getAtmosPacketID() const;

	void writeUChar( unsigned char c );
	void writeChar( char c );
	void writeString( const std::string &str );
	void writeUInt( unsigned int i );
	void writeInt( int i );
	void writeFloat( float f );
	void writeDouble( double d );		

	unsigned char readUChar();
	char readChar();
	std::string readString();
	unsigned int readUInt();
	int readInt();
	float readFloat();
	double readDouble();

	//! get the underling RakNet::BitStream (not advised for public use)
	/*! note that if you use this method, you'll have to provide RakNet as a dependency in your project
		*/
	RakNet::BitStream *getBitStream();

	//! utility function that converts a packet ID to a string containing its name
	static const char *idToString( PacketID id );

	//! set the seek position in the packet's data memory (not advised for public use)
	void setSeekPosition( uint position );

private:
	std::string mRakNetGUID;
	PacketID mPacketID;
	RakNet::BitStream *mBitStream;
};

} // end namespace ATMOS

#endif